<?php
include_once('../includes/settings.php');
include_once('../includes/functions.php');
include_once(inc('sql.php'));
include_once(inc('repository.php'));
$user_id = intval(user_val('id'));
$word_id = intval($_REQUEST['word_id']);
$word = Word::get_by_id($word_id);
$sentences=NULL;
?>


<?php
	$type = strtolower($_REQUEST['type']);
	if($type=='all'){
		$sentences = Sentence::get($word_id,$user_id);
	}elseif ($type=="ilike") {
		$sentences = Sentence::get_mime($word_id,$user_id,0);
	}elseif ($type=='mime') {
		$sentences = Sentence::get_mime($word_id,$user_id);
	}
	if($sentences):
		$ids=array();
		foreach ($sentences as $sentence) {
			$ids[]=$sentence['id'];
		}
		$sentences_collected_by=Sentence::sentences_collected_by($ids,$user_id);
?>
<?php
	foreach ($sentences as $sentence):
?>
	<div class="a_sentence" id="sentence_<?php e($sentence['id'])?>" sentence-id="<?php e($sentence['id'])?>">
		<div class="original"><?php e(highlight_word($sentence['sentence'],$word['word'])); ?></div>
		<div class="translation"><?php e($sentence['translation']) ?></div>
		<div class="actions">
			<?php if($sentence['is_creator']!="1"):?>
				<?php if( is_exsit($sentences_collected_by,'sentence_id',$sentence['id'])):?>
					<span>喜欢(<?php e($sentence['num_of_like']) ?>)</span>
				<?php else: ?>
					<a href="javascript:void(0)" class="like">
					喜欢(<?php e($sentence['num_of_like']) ?>)
					</a>
				<?php endif ?>	
				<a href="javascript:void(0)" class="dislike">
					不喜欢(<?php e($sentence['num_of_dislike']) ?>)
				</a>
			<?php else: ?>
				<a href="javascript:void(0)"  class="edit">
					编辑
				</a>
				<a href="javascript:void(0)" class="remove">
					删除
				</a>
				<span>喜欢&nbsp;(<?php e($sentence['num_of_like']) ?>)</span>
				<span>不喜欢&nbsp;(<?php e($sentence['num_of_dislike']) ?>)</span>
			<?php endif ?>
		</div>
	</div>
<?php endforeach ?>
<?php else: ?>
<span class="grey_small">抱歉，该分类下还没有例句。</span>
<?php endif ?>